package leetcode.code009;

/**
 * 对撞针
 * @author CaoYu
 * @date 2021年8月10日
 * @description
 */
public class Solution2 implements ISolution {

	public static void main(String[] args) {

		int x = 121;
		int y = 122;
		int z = 12321;
		int m = -121;

		print(x);
		print(y);
		print(z);
		print(m);

	}

	public static void print(int x) {
		ISolution solution = new Solution2();
		boolean result = solution.isPalindrome(x);
		System.out.println(x + " " + result);
	}

	@Override
	public boolean isPalindrome(int x) {
		if (x < 0)
			return false;
		String str = String.valueOf(x);
		int l = 0;
		int r = str.length() - 1;
		while (l < r) {
			if (str.charAt(l) != str.charAt(r)) {
				return false;
			}
			l++;
			r--;
		}
		return true;
	}

}
